package WinterHomework.day08;

//压缩字符串  "aabbccdaa"->"a2b2c2d1a2"
public class Demo02 {
    public static void main(String[] args) {
        String str = "aabbccddaa";
        System.out.println(yaSuo(str));
    }

    public static String yaSuo(String str) {
        char[] ch = str.toCharArray();
        StringBuilder sb = new StringBuilder();
        int num = 1;
        char last = ch[0];
        for (int i = 1; i < ch.length; i++) {
            if(ch[i] == last) {
                num++;
            }else {
                sb.append(last);
                sb.append(num);
                last = ch[i];
                num = 1;
            }
        }
        sb.append(last).append(num);
        return sb.toString();
    }
}
